package com.enlorenz.common.util;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
 * ID生成器
 * @author lcb
 */
public class IdGenerator {
    private static final Lock LOCK = new ReentrantLock();
    private static long seedTime = System.currentTimeMillis();
    private static short count = 0;

    /** 构造方法 */
    private IdGenerator() {
    }

    /** 生成ID */
    public static String getId() {
    	LOCK.lock();
        try {
            count++;
        } finally {
            LOCK.unlock();
        }
    	
        String id = "";
        id = String.valueOf(seedTime)+ String.valueOf(count);
        return id;
    }
    
    public static void main(String[] args) {
		System.out.println(IdGenerator.getId());
		System.out.println(IdGenerator.getId());
		System.out.println(IdGenerator.getId());
		System.out.println(IdGenerator.getId());
	}
}
